<cfcomponent>
<cffunction name="getcategories" access="public" returntype="query">
  <cfquery name="qcats" datasource="#request.dsn#">
        SELECT * FROM blog_categories
        ORDER BY cname ASC
        </cfquery>
  <cfreturn qcats>
</cffunction>
<cffunction name="getcategory" access="public" returntype="query">
  <cfargument name="cid" type="numeric" required="yes">
  <cfquery name="qcat" datasource="#request.dsn#">
        SELECT * FROM blog_categories
		WHERE id = <cfqueryparam value="#cid#" cfsqltype="cf_sql_integer">
        </cfquery>
  <cfreturn qcat>
</cffunction>
<cffunction name="getcatcount" access="public" returntype="query">
  <cfquery name="qcatcount" datasource="#request.dsn#">
        SELECT count(*) AS totalrecords FROM blog_categories
        ORDER BY cname ASC
        </cfquery>
  <cfreturn qcatcount>
</cffunction>
<cffunction name="getlatest" access="public" returntype="query">
  <cfargument name="entries" type="numeric" required="no" default="6">
  <cfset todaysdate = #createodbcdatetime(now())#>
  <cfset tomorrowsdate = dateadd("d", 1, todaysdate)>
  <cfquery name="qblog" datasource="#request.dsn#" maxrows="#entries#">
        SELECT * FROM blog_posts
        WHERE b_postedon < #createodbcdatetime(tomorrowsdate)#
		AND status > <cfqueryparam value="0" cfsqltype="cf_sql_integer">
        ORDER BY b_postedon DESC
        </cfquery>
  <cfreturn qblog>
</cffunction>
<cffunction name="getincategory" access="public" returntype="query">
  <cfargument name="cid" type="numeric" required="yes" hint="category id">
  <cfquery name="qblog" datasource="#request.dsn#" maxrows="200">
        SELECT * FROM blog_posts JOIN blog_categories_map ON blog_categories_map.b_id = blog_posts.b_id
        WHERE blog_categories_map.cid = <cfqueryparam value="#cid#" cfsqltype="cf_sql_integer">
		AND blog_posts.status > <cfqueryparam value="0" cfsqltype="cf_sql_integer">        
        ORDER BY b_postedon DESC
        </cfquery>
  <cfreturn qblog>
</cffunction>
<cffunction name="getonday" access="public" returntype="query">
  <cfargument name="da" type="numeric" required="yes" hint="day">
  <cfargument name="mo" type="numeric" required="yes" hint="month">
  <cfargument name="yr" type="numeric" required="yes" hint="year">
  <cfquery name="qblog" datasource="#request.dsn#" maxrows="200">
        SELECT * FROM blog_posts
        WHERE b_day = <cfqueryparam value="#da#" cfsqltype="cf_sql_integer">
        AND b_month = <cfqueryparam value="#mo#" cfsqltype="cf_sql_integer">
        AND b_year = <cfqueryparam value="#yr#" cfsqltype="cf_sql_integer">
		AND status > <cfqueryparam value="0" cfsqltype="cf_sql_integer">        
        ORDER BY b_postedon DESC
        </cfquery>
  <cfreturn qblog>
</cffunction>
<cffunction name="getpostcount" access="public" returntype="numeric">
  <cfargument name="cid" type="numeric" required="no" default="0">
  <cfargument name="view_month" default="0" type="numeric" required="no">
  <cfargument name="view_year" type="numeric" required="yes" hint="year is required.">
  <cfif cid GT 0>
    <cfquery name="qposts" datasource="#request.dsn#">
    SELECT count(*) AS totalrecords FROM blog_posts JOIN blog_categories_map ON blog_categories_map.b_id = blog_posts.b_id
    WHERE cid = <cfqueryparam value="#cid#" cfsqltype="cf_sql_integer">
    <cfif view_month GT 0>AND b_month = <cfqueryparam value="#view_month#" cfsqltype="cf_sql_integer"></cfif>
    AND b_year = <cfqueryparam value="#view_year#" cfsqltype="cf_sql_integer">
    </cfquery>
  <cfelse>
    <cfquery name="qposts" datasource="#request.dsn#">
    SELECT count(*) AS totalrecords FROM blog_posts 
    <cfif view_month GT 0>WHERE b_month = <cfqueryparam value="#view_month#" cfsqltype="cf_sql_integer"> AND<cfelse>WHERE </cfif>
    b_year = <cfqueryparam value="#view_year#" cfsqltype="cf_sql_integer">
    </cfquery>
  </cfif>
  <cfset totalrecords = qposts.totalrecords>
  <cfreturn totalrecords>
</cffunction>
<cffunction name="getallposts" access="public" returntype="query">
  <cfargument name="startrow" default="0" type="numeric" required="no">
  <cfargument name="endrow" default="50" type="numeric" required="no">
  <cfargument name="view_month" default="0" type="numeric" required="no">
  <cfargument name="view_year" type="numeric" required="yes" hint="year is required.">
  <cfargument name="cid" default="0" type="numeric" required="no">
  <cfif cid GT 0>
    <cfquery name="qposts" datasource="#request.dsn#">
    SELECT * FROM blog_posts JOIN blog_categories_map ON blog_categories_map.b_id = blog_posts.b_id
    WHERE blog_categories_map.cid = <cfqueryparam value="#cid#" cfsqltype="cf_sql_integer">
    <cfif view_month GT 0>AND blog_posts.b_month = <cfqueryparam value="#view_month#" cfsqltype="cf_sql_integer"></cfif>
    AND blog_posts.b_year = <cfqueryparam value="#view_year#" cfsqltype="cf_sql_integer">
    LIMIT #startrow#, #endrow#
    </cfquery>
  <cfelse>
    <cfquery name="qposts" datasource="#request.dsn#">
    SELECT * FROM blog_posts 
    <cfif view_month GT 0>WHERE b_month = <cfqueryparam value="#view_month#" cfsqltype="cf_sql_integer">AND<cfelse>WHERE </cfif>
    b_year = <cfqueryparam value="#view_year#" cfsqltype="cf_sql_integer">
    LIMIT #startrow#, #endrow#
    </cfquery>
  </cfif>
  <cfreturn qposts>
</cffunction>
<cffunction name="getmetadata" access="public" returntype="query">
  <cfargument name="filename" type="string" required="yes" hint="blog file name that gets this meta data">
  <cfquery name="qblog" datasource="#request.dsn#" maxrows="#entries#">
        SELECT * FROM core_meta
        WHERE = <cfqueryparam value="#filename#" cfsqltype="cf_sql_varchar">
        </cfquery>
  <cfreturn qmeta>
</cffunction>
<cffunction name="getpost" access="public" returntype="query">
  <cfargument name="b_id" type="numeric" required="yes" default="0">
  <cfquery name="qblog" datasource="#request.dsn#" maxrows="1">
        SELECT * FROM blog_posts
		WHERE b_id = <cfqueryparam value="#b_id#" cfsqltype="cf_sql_integer">
        </cfquery>
  <cfreturn qblog>
</cffunction>
<cffunction name="showtop" access="public" returntype="void" output="yes">
  <cfinvoke method="getlatest" returnvariable="qblog"> <cfoutput query="qblog">
    <div id="b_date">#b_postedon#</div>
    <div id="b_title">#b_title#</div>
    <div id="b_brief">#left(b_brief, 140)#...</div>
    <div id="readmore">
      <div id="button_readmore" onClick="window.location.href = '#request.absolutepath#blog/#b_year#/#b_month#/#b_day#/#b_file#';">read more</div>
    </div>
    <div id="blog_line"></div>
  </cfoutput>
</cffunction>
<cffunction name="showarchive" access="public" returntype="void" output="yes">
  <cfargument name="maxarchives" default="20" required="no">
  <cfargument name="startat" default="1" required="no">
  <cfinvoke method="getlatest" entries="#maxarchives#" returnvariable="qblog">
  <div id="archives_wrapper">
    <cfloop query="qblog" startrow = '#startat#'>
      <cfoutput>
        <div id="archives_date">#dateformat(b_postedon, 'mm.dd.yyyy')#</div>
        <div id="archives_title"><a href = "#request.absolutepath#blog/#b_year#/#b_month#/#b_day#/#b_file#" target="_top">#b_title#</a></div>
        <div id="archives_spacer">&nbsp;</div>
      </cfoutput>
    </cfloop>
  </div>
</cffunction>
<cffunction name="showcal" access="remote" returntype="void" output="yes">
  <cfargument name="mo" default="#datepart("m", now())#" required="no">
  <cfargument name="yr" default="#datepart("yyyy", now())#" required="no">
  <cfajaximport tags="cfform">
  <cfdiv id="caldiv">
  <cfform name="calform" id="calform" method="post" action="cfcs/blog.cfc?method=showcal">
  <cfset dateob=CreateDate(yr,mo,1)>
  <cfset ly = #yr#>
  <cfset ny = #yr#>
  <cfset daybuilder = arraynew(1)>
  <cfloop index="c" from="1" to="#DaysInMonth(DateOb)#">
    <cfset daybuilder[#c#]="no">
  </cfloop>
  <cfquery name="load_calendar" datasource="#request.dsn#">
    SELECT b_postedon,(day(b_postedon)) AS getthisday
    FROM  blog_posts 
    WHERE  (b_postedon >= #CreateDate(Year(DateOb),Month(DateOb),1)#) and (b_postedon <= #CreateDate(Year(DateOb),Month(DateOb),DaysInMonth(DateOb))#)
    </cfquery>
  <cfquery name="qrygetyears" datasource="#request.dsn#">
    SELECT DISTINCT (year(b_postedon)) AS blog_year
    FROM  blog_posts 
    </cfquery>
  <cfoutput query="load_calendar" group="b_postedon">
    <cfset daybuilder[#getthisday#]="yes">
  </cfoutput>
  <div align="center" style="padding: 8px;">
    <table width="231" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td colspan="7" align="center"><table border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td><select name="mo" onChange="ColdFusion.navigate('#request.absolutepath#cfcs/blog.cfc?method=showcal','caldiv',null,null,'post','calform');return false;" id="blog_cal_month">
                  <cfoutput>
                    <option class="caltitle" value="1" <cfif mo eq 1> selected="selected"</cfif>>Jan</option>
                    <option class="caltitle" value="2" <cfif mo eq 2> selected="selected"</cfif>>Feb</option>
                    <option class="caltitle" value="3" <cfif mo eq 3> selected="selected"</cfif>>Mar</option>
                    <option class="caltitle" value="4" <cfif mo eq 4> selected="selected"</cfif>>Apr</option>
                    <option class="caltitle" value="5" <cfif mo eq 5> selected="selected"</cfif>>May</option>
                    <option class="caltitle" value="6" <cfif mo eq 6> selected="selected"</cfif>>Jun</option>
                    <option class="caltitle" value="7" <cfif mo eq 7> selected="selected"</cfif>>Jul</option>
                    <option class="caltitle" value="8" <cfif mo eq 8> selected="selected"</cfif>>Aug</option>
                    <option class="caltitle" value="9" <cfif mo eq 9> selected="selected"</cfif>>Sep</option>
                    <option class="caltitle" value="10" <cfif mo eq 10> selected="selected"</cfif>>Oct</option>
                    <option class="caltitle" value="11" <cfif mo eq 11> selected="selected"</cfif>>Nov</option>
                    <option class="caltitle" value="12" <cfif mo eq 12> selected="selected"</cfif>>Dec</option>
                  </cfoutput>
                </select>
              </td>
              <td><select name="yr" onChange="ColdFusion.navigate('#request.absolutepath#cfcs/blog.cfc?method=showcal','caldiv',null,null,'post','calform');return false;" id="blog_cal_year">
                  <cfloop query="qryGetYears">
                    <cfoutput>
                      <option class="caltitle" value="#blog_year#" <cfif yr IS #blog_year#>selected="selected"</cfif>>#blog_year#</option>
                    </cfoutput>
                  </cfloop>
                  <!---Display the current year--->
                  <cfif qryGetYears.recordcount IS 0>
                    <cfset thisyear = dateformat(now(), "yyyy")>
                    <cfset toyear = thisyear - 10>
                    <cfoutput>
                      <cfloop from="#thisyear#" to="#toyear#" index="years" step="-1">
                        <option class="caltitle" value="#years#" <cfif yr IS #years#>selected="selected"</cfif>>#years#</option>
                      </cfloop>
                    </cfoutput>
                  </cfif>
                </select>
              </td>
            </tr>
          </table></td>
      </tr>
      <tr>
        <td width="33" height="20" align="center" class="cal">sun</td>
        <td width="33" height="20" align="center" class="cal">mon</td>
        <td width="33" height="20" align="center" class="cal">tue</td>
        <td width="33" height="20" align="center" class="cal">wed</td>
        <td width="33" height="20" align="center" class="cal">thu</td>
        <td width="33" height="20" align="center" class="cal">fri</td>
        <td width="33" height="20" align="center" class="cal">sat</td>
      </tr>
      <tr>
      
      <cfset FIRSTOFMONTH=CreateDate(Year(DateOb),Month(DateOb),1)>
      <cfset TOPAD=DayOfWeek(FIRSTOFMONTH) - 1>
      <cfset PADSTR=RepeatString("<td width=""28"" height=""18"">&nbsp;</td>",TOPAD)>
      <cfoutput>#PADSTR#</cfoutput>
      <cfset DW=TOPAD>
      <cfloop INDEX="x" FROM="1" TO="#DaysInMonth(DateOb)#">
      
      <cfoutput>
        <cfif #daybuilder[x]# eq "no">
          <td height="18" class="cmoff" id="c#x#" align="center" valign="middle"><span>#x#</span> </td>
          <cfelse>
          <td height="18" class="dmon" id="d#x#" align="center" valign="middle" onclick="window.location.href = '#request.absolutepath#index.cfm?c=blog&a=showday&da=#x#&mo=#mo#&yr=#yr#';"><a href="#request.absolutepath#index.cfm?c=blog&a=showday&da=#x#&mo=#mo#&yr=#yr#">#x#</a> </td>
        </cfif>
      </cfoutput>
      <cfset DW=DW + 1>
      <cfif DW EQ 7>
        </tr>
        
        <cfset DW=0>
        <cfif X LT DaysInMonth(DateOb)>
          <tr>
          
        </cfif>
      </cfif>
      </cfloop>
      
      <cfset TOPAD=7 - DW>
      <cfif TOPAD LT 7>
        <cfset PADSTR=RepeatString("<td height=""18"" class=""calpad"">&nbsp;</td>",TOPAD)>
        <cfoutput>#PADSTR#</cfoutput>
        </tr>
        
      </cfif>
      <!--- display calendar end --->
    </table>
  </div>
  </cfform>
  </cfdiv>
</cffunction>
<cffunction name="readpost" access="public" returntype="void" output="yes">
  <cfargument name="bid" default="0" required="Yes" type="numeric">
  <cfinvoke method="getpost" b_id="#bid#" returnvariable="qpost"> <cfoutput query="qpost">
    <div class="blog_pad1">
      <div class="blog_item">
        <div class="blog_headlines">#b_title#</div>
        <div class="blog_date">#DayofWeekAsString(DayOfWeek(b_postedon))#, #Day(b_postedon)# #MonthAsString(Month(b_postedon))# #Year(b_postedon)# #TimeFormat(b_postedon, "h:mm tt")# </div>
        <div class="clear"></div>
        <cfif fileexists('#request.basepath#docs/blog/#b_file#')>
          <div class="blog_entry">
            <cfinclude template="#request.absolutepath#docs/blog/#b_file#">
          </div>
          <cfelse>
          <div class="blog_entry">Article has been removed.</div>
        </cfif>
        <div class="blog_bigclear"></div>
        <div class="blog_clear"></div>
      </div>
    </div>
  </cfoutput>
</cffunction>
<cffunction name="showcats" access="public" returntype="void" output="yes" hint="shows a listing of the categories">
  <cfinvoke method="getcategories" returnvariable="qcats">
  <div id="blog_categories_wrapper"> <cfoutput query="qcats">
      <div id="blog_category"><a href = "#request.absolutepath#index.cfm?c=blog&a=category&cid=#id#">#cname#</a></div>
    </cfoutput> </div>
</cffunction>
<cffunction name="showdisqus" access="public" returntype="void" output="yes" hint="shows the comments">
  <cfoutput>
    <div id="content_body_top"></div>
    <div id="content_body_middle">
      <div id="contents_container">
        <div id="blog_comments">
          <div id="disqus_thread"></div>
          <script type="text/javascript">
    /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
    var disqus_shortname = '#request.blog.disqusname#'; // required: replace example with your forum shortname

    /* * * DON'T EDIT BELOW THIS LINE * * */
    (function() {
        var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
        dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();
</script>
          <noscript>
          Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a>
          </noscript>
          <a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a> </div>
      </div>
    </div>
    <div id="content_body_bottom"></div>
  </cfoutput>
</cffunction>
</cfcomponent>
